clear all; close all; clc;

load Hd;

N = 1e6;
Fd = 44.2e6;
Td = 1/Fd;
T = N * Td; 

N0 = 1;
stdn = N0 /(2*Td);
n = stdn * randn(1, N);

y = filter(Hd.numerator, 1, n);

figure(1);
f = 0:1/T:(1/Td-1/T);
Sf = 20*log10(abs(fft(y)))
Sf = Sf - max(Sf) + 1;
plot(f/1e6, Sf);
xlim([0 Fd/2/1e6])
xlabel('f, MHz')
grid on


tmax = 0.1; t = 0:Td:tmax;

N_PRN = 1023; T_PRN = 0.001;
PRN = sign(randn(1, N_PRN));
phase_h = mod(t/T_PRN, 1)*N_PRN
ind_h = fix(mod(t/T_PRN, 1)*N_PRN) + 1;
h = PRN(ind_h);

A = 2; 
f0 = 6e6; 
phi = pi/4;
u = A * h .* cos(2*pi*f0*t + phi);

figure(2)
subplot(4,1,1)
plot(t, u)
subplot(4,1,2)
plot(t, h)
subplot(4,1,3)
plot(t, phase_h)
subplot(4,1,4)
plot(t, ind_h)

y = filter(Hd.numerator, 1, u);
f = 0:1/tmax:(1/Td);
Sf = 20*log10(abs(fft(y)));
Sf = Sf - max(Sf) + 1;

figure(3)
plot(f/1e6, Sf);
xlim([0 Fd/2/1e6])
xlabel('f, MHz')
grid on
